<?	/*

	// File:	file_mng.inc.phps
	// Purpose:	internal ftp client
	// Creation:	2001-10-07 @ 2001-12-10
	// Author:	Tom|420
	//		Jonathan Haskins <jhaskins@killobyte.com>
	//		Peter Drake (c) 2004
	*/


if (!@is_dir(getenv('TMPDIR'))) {

    putenv('TMPDIR='.$cfg['tmpdir']);

}


$dir = $data['dir'];


// ************************** CONFIG *******************************************

// Date format from translation file
$dateformat  = $T['date_time_format'];


// number of lines of text to show at once in the viewer
$fviewlen = $cfg['fviewlen'];



// Icons

$icon_dir = '/icon/';

$s_icon_size = 16;  // width/height of small icons

$l_icon_size = 34;  // width/height of large icons



$icons['lfolder']  = 'folder34.gif';		// folders

$icons['sfolder']  = 'folder16.gif';

$icons['lofolder'] = 'folder_open34.gif';	// open folder

$icons['sofolder'] = 'folder_open16.gif';

$icons['lhomefld'] = 'folder_home34.gif';	// link to user's root

$icons['shomefld'] = 'folder_home16.gif';

$icons['lhtmlfld'] = 'folder_html34.gif';	// /web/

$icons['shtmlfld'] = 'folder_html16.gif';

$icons['llckfld']  = 'folder_locked34.gif';	// dir protected by .htaccess

$icons['slckfld']  = 'folder_locked16.gif';

$icons['sparent']  = 'parent16.gif';

$icons['lhtml']    = 'html34.gif';

$icons['shtml']    = 'html16.gif';

$icons['ltxt']     = 'txt34.gif';

$icons['stxt']     = 'txt16.gif';

$icons['limg']     = 'image34.gif';

$icons['simg']     = 'image16.gif';

$icons['larc']     = 'archive34.gif';

$icons['sarc']     = 'archive16.gif';

$icons['lmedia']   = 'video34.gif';

$icons['smedia']   = 'video16.gif';

$icons['llog']     = 'log34.gif';

$icons['slog']     = 'log16.gif';

$icons['ldoc']     = 'document34.gif';

$icons['sdoc']     = 'document16.gif';

$icons['lother']   = 'unknown34.gif';

$icons['sother']   = 'unknown16.gif';



$file_icon = '/icon/document.gif';	// small icon for files

$pfolder_icon = '/icon/parent.gif';	// small icon for cdup



// Extensions for file types (passed as a regex that checks end of filename)

$file_types['html']	= $cfg['file_types-html'];
$file_types['txt']	= $cfg['file_types-txt'];
$file_types['img']	= $cfg['file_types-img'];
$file_types['arc']	= $cfg['file_types-arc'];
$file_types['media']	= $cfg['file_types-media'];
$file_types['doc']	= $cfg['file_types-doc'];
$file_types['log']	= $cfg['file_types-log'];


// ********************** INIT **********************************



if (empty($action)) $action = '';

if (empty($htpasswdcontents)) $htpasswdcontents = '';

if (empty($htaccesscontents)) $htaccesscontents = '';




// remove any ../ from requested file so they can't

// ascend into forbidden directories

$dir = str_replace('../', '', rtrim($dir, '/').'/');



// strip possible leading and trailing slashes from dir

$dir = trim($dir, '/');



if ($cfg['users_chrooted']) {

	$currentdir = '/'.$dir;

} else {

	// strip possible trailing slash from rootdir

	$rootdir = rtrim($personaldata['root'], '/');



	if (!empty($dir)) {

		$currentdir = $rootdir.'/'.$dir;

	} else {

		$currentdir = $rootdir;

	}

}



$domain = $domaindata['host'].'.'.$domaindata['domain'];

$webpath = ereg_replace("^/web/", '', strstr($currentdir, '/web/'));





// *****************************************************************************

// *** ACTION: newdir (new directory)

// *** creates a new directory

if ($action == 'newdir') {



	// Shows the form for creating a new directory

	if (!isset($_POST['confirm'])) {

		?>

		<form action="<?=$current_url;?>&action=newdir" method="post">
		<input type="hidden" name="data[dir]" size="50" value="<?=$dir?>">


		<p><?=$T['Create new directory in'];?>: <b><?=$currentdir?></b></p>

		<p><?=$T['Name'];?>: <input type="text" name="data[dir_name]" size="50"></p>

		<table><tr>

		<td>

			<input type="submit" name="confirm" value="<?=$T['Create']?>">

			</form>

		</td>

		<form action="<?=$current_url;?>&data[dir]=<?=$dir?>" method="post">

		<td>

			<input type="submit" name="cancel" value="<?=$T['Cancel']?>">

			</form>

		</td>

		</tr></table>

		<?



	}



	// Create a new directory

	elseif ($userdata['type'] != 'demo') {



		if (!$FTPid = filemanager_login($personaldata)) { return; }



		if (@ftp_mkdir($FTPid, $currentdir.'/'.$data['dir_name'])) {

			echo '<p>'.$T['Successfully created '].$T['Dir']." <b>$currentdir/".$data['dir_name']."</b></p>\n";

		} else {

			echo '<p>'.$T['Failed to create '].$T['Dir']." <b>$currentdir/".$data['dir_name']."</b>! ".$T['IncorrectPermission']."</p>\n";

		}



		@ftp_quit($FTPid);



		echo '<p><a href="/?url='.$url.'&cp='.$cp.'&user='.$user.'&data[dir]='.$dir.'">'.$T['Return'].'</a>'."\n";

	} else {

		echo "<center>".$T['err']['demo user']."<br><a href='/?url=$url&cp=$cp&user=$user&data[dir]=$dir'>".$T['Return']."</a></center>\n";

	}

}



// *****************************************************************************

// *** ACTION: upload (file upload)

// *** Receives uploaded files, transfers from tmp dir to final dir through FTP

elseif ($action == 'upload') {



	// Shows the form for selecting files to upload

	if (!isset($_POST['confirm'])) {

		if (!isset($data['upload_files_num'])) {

			$upload_files_num = $cfg['upload_files_num'];

		} else {

			$upload_files_num = intval($data['upload_files_num']);

		}

		?>

		<form action="<?=$current_url;?>&data[dir]=<?=$dir?>&action=upload" method="post">

		<?=$T['Files to upload: '];?><select name="data[upload_files_num]" onchange="form.submit();">

		<?

			for ($i=1; $i<=20; $i++) {

				echo '<option value="'.$i.'"';

				if ($upload_files_num == $i) { echo " selected "; }

				echo '>'.$i.'</option>\n';

			}

		?>

		</select>

		</form>

		<form enctype="multipart/form-data" action="<?=$current_url;?>&action=upload" method="post">
		<input type=hidden name=data[dir] value="<?=$dir?>">

		<table border="0" width="100%">

		<?

		for ($i = 1; $i <= $upload_files_num; $i++) {

			echo '<tr><td align=right width=60>'.$T['File']." ".$i.': </td><td><input type="file" name="uplfile'.$i.'" size="50"></td></tr>'."\n";

		}

		?>

		</table>

		<table><tr>

		<td>

			<input type="submit" name="confirm" value="<?=$T['Upload']?>">

			</form>

		</td>

		<form action="<?=$current_url;?>&data[dir]=<?=$dir?>" method="post">
		<td>

			<input type="submit" name="cancel" value="<?=$T['Cancel']?>">

			</form>

		</td>

		</tr></table>

		<?

	}



	elseif ($userdata['type'] != 'demo') {

		if (!$FTPid = filemanager_login($personaldata)) { return; }



		// upload each temp file to the new path as the original name

		foreach($_FILES AS $val) {

			if (file_exists($val['tmp_name'])) {

				if (ereg('^(txt|html|log|doc)$', ftp_file_type($val['name'], $file_types)))

					$mode = FTP_ASCII;

				else

					$mode = FTP_BINARY;



				if (@ftp_put($FTPid, $currentdir.'/'.$val['name'], $val['tmp_name'], $mode))

					echo '<p>'.$T['UploadSuccess'].' <b>'.$val['name']."</b></p>\n";

				else

					echo '<p>'.$T['UploadError'].' <b>'.$val['name']."</b></p>\n";

			}

		}



		@ftp_quit($FTPid);



		echo '<p><a href="/?url='.$url.'&cp='.$cp.'&user='.$user.'&data[dir]='.$dir.'">'.$T['Return'].'</a>'."\n";

	} else {

		echo "<center>".$T['err']['demo user']."<br><a href='/?url=$url&cp=$cp&user=$user&data[dir]=$dir'>".$T['Return']."</a></center>\n";

	}

}



//******************************************************************************

// *** ACTION: hta

// *** Edit .htaccess file





elseif ($action == 'hta') {

	if (!isset($data['dirlist'])) {
		$dirlist = false;
	} else {
		$dirlist = $data['dirlist'];
	}

	if (!isset($data['protected'])) {
		$protected = false;
	} else {
		$protected = $data['protected'];
	}

	if (!isset($data['hotlink'])) {
		$hotlink = false;
	} else {
		$hotlink = $data['hotlink'];
	}

	if (!isset($data['allowall'])) {
		$allowall = 'server';
	} else {
		$allowall = $data['allowall'];
	}
	if (!isset($data['htpasswd'])) {
		$htpasswd = false;
	} else {
		$htpasswd = $data['htpasswd'];
	}
	if (!isset($data['htuser'])) {
		$htuser = false;
	} else {
		$htuser = $data['htuser'];
	}
	if (!isset($data['ipaddress'])) {
		$ipaddress = false;
	} else {
		$ipaddress = $data['ipaddress'];
	}
	if (!isset($data['domainuser'])) {
		$domainuser = false;
	} else {
		$domainuser = $data['domainuser'];
	}

	if (!$FTPid = filemanager_login($personaldata)) { return; }


	$tmp_name = '/tmp/php'.uniqid(getmypid());

	$tmp2_name = '/tmp/php'.uniqid(getmypid());



	$protected_search  = "/AuthType Basic" . "\n";

	$protected_search .= "AuthName protected-area" . "\n";

	$protected_search .= "AuthUserFile .*" . "\n";

	$protected_search .= "require valid-user" . "/";



	$hotlink_search = "/RewriteEngine On\n";

	$hotlink_search .= "RewriteCond \%\{HTTP_REFERER\} (.*)\n";

	$hotlink_search .= "RewriteRule \\\.\(gif\|jpg\|png\|jpeg\)\\$ \- \[F\]/s";



	$dirlist_search = "/Options \+Indexes/";

	$allowall_search = "/Allow from All/";

	$allowspecific_search = '/Allow from [0-9](.*)/';

	$denyall_search = "/Deny from All/";

	$denyspecific_search = '/Deny from [0-9](.*)/';

	$getspecific_search = '/((Deny|Allow) from ([0-9].*))/';


	if (!$list = @ftp_rawlist($FTPid, '-a '.$currentdir)) {

		echo '<p>'.$T['FTPerror'].'!</p>';

		@ftp_quit($FTPid);

		return;

	} else {
		$list = implode(" ", $list);
	}

	if (strstr($list, ".htaccess")) {
	if (@ftp_get($FTPid, $tmp_name, $currentdir.'/.htaccess', FTP_ASCII)) {

		$htaccessfile = fopen($tmp_name, "r");

      		while (!feof($htaccessfile)) {

			$htaccesscontents .= fread($htaccessfile, 1024);

		}

		fclose($htaccessfile);

		$htaccesscontents = trim($htaccesscontents);

	}
	}

	if (strstr($list, ".htpasswd")) {
	if (@ftp_get($FTPid, $tmp_name, $currentdir.'/.htpasswd', FTP_ASCII)) {

		$htpasswdfile = fopen($tmp_name, "r");

      		while (!feof($htpasswdfile)) {

			$htpasswdcontents .= fread($htpasswdfile, 1024);

		}

		fclose($htpasswdfile);

		$htpasswdcontents = trim($htpasswdcontents);

	}
	}


    if (isset($data['action']) && ($userdata['type'] != 'demo'))   {

		// make .htaccess and .htpasswd

		$htpath = (($cfg['users_chrooted']) ? $cfg['webdir'] . "/" . $domaindata['domain'] : "") . $currentdir . "/.htpasswd";

		switch($data['action']) {

			case "adduser":

				if ($domainuser != "") {

					$SQL = "SELECT username, DECODE(password,'".$cfg['key']."') AS password FROM users inner join domains ON users.id = domains.id WHERE domain = '".$domaindata['domain']."' AND username = '".$domainuser."'";

					$curuserlist = mysql_query($SQL);

					if ($row = mysql_fetch_array($curuserlist)) {

						$htpasswdcontents .= "\n".$row["username"].":".crypt($row["password"],CRYPT_STD_DES);

					}

				} elseif ($htuser != "" && $htpasswd != "") {

	    	    	$htpasswdcontents .= "\n$htuser:".crypt($htpasswd,CRYPT_STD_DES);

	    	    }

				break;

			case "deleteuser":

				$htpasswdcontents = str_replace($htuser, "", $htpasswdcontents);

				break;

			case "addip":

				$ipaddress = trim($ipaddress);

				if (preg_match($allowall_search, $htaccesscontents)) {

					$allowall = "on";

				} elseif (preg_match($denyall_search, $htaccesscontents)) {

					$allowall = "off";

				} else {

					$allowall = "server";

				}

				if ($allowall == "on") {

					$htaccesscontents .= "\nDeny from ".$ipaddress;

				} else {

					$htaccesscontents .= "\nAllow from ".$ipaddress;

				}

				break;

			case "deleteip":

				$ipaddress = trim($ipaddress);

				if (preg_match($allowall_search, $htaccesscontents)) {

					$allowall = "on";

				} elseif (preg_match($denyall_search, $htaccesscontents)) {

					$allowall = "off";

				} else {

					$allowall = "server";

				}

				if ($allowall == "on") {

					$htaccesscontents = str_replace($ipaddress, "", $htaccesscontents);

				} else {

					$htaccesscontents = str_replace($ipaddress, "", $htaccesscontents);

				}

				break;

			case "changepass":

				$htpasswdcontents = preg_replace("/$htuser:(.*)/", "\${1}:".crypt($htpasswd,CRYPT_STD_DES), $htpasswdcontents);

				break;

			case "settings":

				if ($protected == "on") {

					$htprotect  = "AuthType Basic" . "\n";

					$htprotect .= "AuthName protected-area" . "\n";

					$htprotect .= "AuthUserFile $htpath" . "\n";

					$htprotect .= "require valid-user" . "\n";

					if (!preg_match($protected_search, $htaccesscontents)) {

						$htaccesscontents .= "\n".$htprotect;

					} else {

						$htaccesscontents = preg_replace($protected_search, $htprotect, $htaccesscontents);

					}

				} else {

					$htaccesscontents = preg_replace($protected_search, "", $htaccesscontents);

				}

				if ($hotlink == "on") {

					$SQL = "SELECT domains.domain FROM domains inner join domains as domains2 ON domains.owner = domains2.id WHERE domains.type = 'pointer' AND domains2.domain = '".$domaindata['domain']."'";

					$res = mysql_query($SQL);

					$hthotlink = "RewriteEngine On\n";

					$hthotlink .= "RewriteCond %{HTTP_REFERER} !^$\n";

					$hthotlink .= "RewriteCond %{HTTP_REFERER} !^http://([a-z]|[A-Z]|[0-9]|\.)*".$domaindata['domain']."/.*$ [NC]\n";

					for ($i=0; $row=mysql_fetch_array($res); $i++) {

						$hthotlink .= "RewriteCond %{HTTP_REFERER} !^http://([a-z]|[A-Z]|[0-9]|\.)*".$row['domain']."/.*$ [NC]\n";

					}

					$hthotlink .= "RewriteRule \.(gif|jpg|png|jpeg)$ - [F]\n";

					if (!preg_match($hotlink_search, $htaccesscontents)) {

						$htaccesscontents .= "\n".$hthotlink;

					} else {

						$htaccesscontents = preg_replace($hotlink_search, $hthotlink, $htaccesscontents);

					}

				} else {

					$htaccesscontents = preg_replace($hotlink_search, "", $htaccesscontents);

				}

				if ($dirlist == "on") {

					$dirlist = "Options +Indexes";

					if (!preg_match($dirlist_search, $htaccesscontents)) {

						$htaccesscontents .= "\n".$dirlist;

					} else {

						$htaccesscontents = preg_replace($dirlist_search, $dirlist, $htaccesscontents);

					}

				} else {

					$htaccesscontents = preg_replace($dirlist_search, "", $htaccesscontents);

				}

				if ($allowall == "on") {

					$allowall = "Allow from All";

					if (!preg_match($allowall_search, $htaccesscontents)) {

						$htaccesscontents .= "\n".$allowall;

					} else {

						$htaccesscontents = preg_replace($allowall_search, $allowall, $htaccesscontents);

					}

				} else {

					$htaccesscontents = preg_replace($allowall_search, "", $htaccesscontents);

					$htaccesscontents = preg_replace($denyspecific_search, "", $htaccesscontents);

				}

				if ($allowall == "off") {

					$denyall = "Deny from All";

					if (!preg_match($denyall_search, $htaccesscontents)) {

						$htaccesscontents .= "\n".$denyall;

					} else {

						$htaccesscontents = preg_replace($denyall_search, $denyall, $htaccesscontents);

					}

				} else {

					$htaccesscontents = preg_replace($denyall_search, "", $htaccesscontents);

					$htaccesscontents = preg_replace($allowspecific_search, "", $htaccesscontents);

				}

				if ($allowall == "server") {

					$htaccesscontents = preg_replace($denyall_search, "", $htaccesscontents);

					$htaccesscontents = preg_replace($allowspecific_search, "", $htaccesscontents);

					$htaccesscontents = preg_replace($allowall_search, "", $htaccesscontents);

					$htaccesscontents = preg_replace($denyspecific_search, "", $htaccesscontents);

				}

				break;

		}



        $htaccesscontents = trim($htaccesscontents);
		file_put_contents($tmp_name, $htaccesscontents);



		$htpasswdcontents = trim($htpasswdcontents);
		file_put_contents($tmp2_name, $htpasswdcontents);

		if (@ftp_put($FTPid, $currentdir.'/.htaccess', $tmp_name, FTP_ASCII) && @ftp_put($FTPid, $currentdir.'/.htpasswd', $tmp2_name, FTP_ASCII)) {

			echo "<ul><li><b>".$T['Changes were successful'].".</b></li></ul>\n";

		} else {

			echo '<p>'.$T['IncorrectPermission']."</p>\n";

		}



	} elseif (isset($_POST['htpasswd']) && ($userdata['type'] == 'demo')) {

		echo "<center>".$T['err']['demo user']."<br></center>\n";

	}



	if ($htpasswdcontents) {

		preg_match_all("/(.*):(.*)/", $htpasswdcontents, $userarray);

	}



	if ($htaccesscontents) {

		preg_match_all($getspecific_search, $htaccesscontents, $iparray);

	}

	// display form

	?>

		<img src="<?=$icon_dir?><?=$icons['lofolder']?>" width="<?=$l_icon_size?>" height="<?=$l_icon_size?>"><b><?=$currentdir?></b> | <a href='/?url=<?=$url;?>&cp=<?=$cp;?>&user=<?=$user;?>&data[dir]=<?=$dir;?>'><?=$T['Return'];?></a>

		<p align=center>



		<?

		if (preg_match($protected_search, $htaccesscontents)) {

			$protected = true;

		}



		if (preg_match($hotlink_search, $htaccesscontents)) {

			$hotlink = true;

		}



		if (preg_match($dirlist_search, $htaccesscontents)) {

			$dirlist = true;

		}



		if (preg_match($allowall_search, $htaccesscontents)) {

			$allowall = "on";

		} elseif (preg_match($denyall_search, $htaccesscontents)) {

			$allowall = "off";

		} else {

			$allowall = "server";

		}



		?>

		<form action="/?url=<?=$url?>&cp=<?=$cp?>&user=<?=$user?>&action=hta" method="post">
		<input type=hidden name=data[dir] value="<?=$dir?>">

		<p align=center>

		<input type=hidden name=data[action] value='settings'>

		<table border="0" cellspacing="0" cellpadding="0"><tr><td>

		<table border="0" cellspacing="0" cellpadding="0" class="tblbg"><tr><td>

		<table border="0" cellspacing="1" width=350>

		<tr>

			<Td class="tbltop" colspan="3"><?=$T['Modify Settings'];?></td>

		</tr>

		<tr>

			<Td class="row1"><div align=right><?=$T['Password protect this directory'];?>: </div></td><td class="row2"><input type="checkbox" name="data[protected]" <?=(($protected) ? " checked" : "");?>></td>

		</tr>

		<tr>

			<Td class="row1"><div align=right><?=$T['Hot-link Image Protection'];?>: </div></td><td class="row2"><input type="checkbox" name="data[hotlink]" <?=(($hotlink) ? " checked" : "");?>></td>

		</tr>

		<tr>

			<Td class="row1"><div align=right><?=$T['Allow Directory Listing'];?></div></td><td class="row2"><input type="checkbox" name="data[dirlist]" <?=(($dirlist) ? " checked" : "");?>></td>

		</tr>

		<tr>

			<Td class="row1" valign=top><div align=right><?=$T['Default Access'];?>: </div></td><td class="row2"><input type="radio" name="data[allowall]" value="server" <?=(($allowall == "server") ? " checked" : "");?>><?=$T['Server Default'];?><br><input type="radio" name="data[allowall]" value="on" <?=(($allowall == "on") ? " checked" : "");?>><?=$T['Allow All, '].$T['Deny List'];?><br><input type="radio" name="data[allowall]" value="off" <?=(($allowall == "off") ? " checked" : "");?>><?=$T['Deny All, '].$T['Allow List'];?></td>

		</tr>

		</table>

		</td></tr></table>

			<div align=right><nobr>

			<input type="submit" value="<?=$T['Apply'];?>" class="check">



    	    </nobr></div>

		</td></tr></table>

		</p>

		</form>



	<? if ($allowall != "server") { ?>

		<br>

		<form action="/?url=<?=$url?>&cp=<?=$cp?>&user=<?=$user?>&action=hta" method="post">
		<input type=hidden name=data[dir] value="<?=$dir?>">

		<p align=center>

		<input type=hidden name=data[action] value='addip'>

		<table border="0" cellspacing="0" cellpadding="0"><tr><td>

		<table border="0" cellspacing="0" cellpadding="0" class="tblbg"><tr><td>

		<table border="0" cellspacing="1" width=350>

		<tr>

			<Td class="tbltop" colspan="3"><?=$T['Add to '].(($allowall == "on") ? $T['Deny List'] : $T['Allow List']);?></td>

		</tr>

		<tr>

			<td class="row1" width="50%"><div align=right><?=$T['IP Address'];?>: </div></td>

			<td class="row2" align=left width="50%"><input type="text" name="data[ipaddress]"></td>

		</tr>

		</table>

		</td></tr></table>

			<div align=right><nobr>

			<input type="submit" value="<?=$T['Add'];?>" class="check">



    	    </nobr></div>

		</td></tr></table>

		</p>

		</form>



		<? if (is_array($iparray) && ($iparray[0][0] != "")) { ?>



		<form action="/?url=<?=$url?>&cp=<?=$cp?>&user=<?=$user?>&action=hta" method="post">
		<input type=hidden name=data[dir] value="<?=$dir?>">
		<p align=center>

		<input type=hidden name=data[action] value='deleteip'>

		<table border="0" cellspacing="0" cellpadding="0"><tr><td>

		<table border="0" cellspacing="0" cellpadding="0" class="tblbg"><tr><td>

		<table border="0" cellspacing="1" width=350>

		<tr>

			<Td class="tbltop" colspan="3"><?=$T['Remove from '].(($allowall == "on") ? $T['Deny List'] : $T['Allow List']);?></td>

		</tr>

		<tr>

			<td class="row1" width="50%"><div align=right><?=$T['IP Address'];?>: </div></td>

			<td class="row2" align=left width="50%">

			<select name=data[ipaddress]>

			<?

				for($i=0; $i<sizeOf($iparray[3]); $i++) {

					echo "<option value='".$iparray[0][$i]."'>".$iparray[3][$i]."</option>";

				}

			?>

			</td>

		</tr>

		</table>

		</td></tr></table>

			<div align=right><nobr>

			<input type="submit" value="<?=$T['Delete'];?>" class="check">



    	    </nobr></div>

		</td></tr></table>

		</p>

		</form>

		<? }

	 }?>



	<? if ($protected) {



		$SQL = "SELECT username FROM users inner join domains ON users.id = domains.id WHERE domain = '".$domaindata['domain']."'";

		$curuserlist = mysql_query($SQL);



	?>

		<br>

		<form action="/?url=<?=$url?>&cp=<?=$cp?>&user=<?=$user?>&action=hta" method="post">
		<input type=hidden name=data[dir] value="<?=$dir?>">

		<p align=center>

		<input type=hidden name=data[action] value='adduser'>

		<table border="0" cellspacing="0" cellpadding="0"><tr><td>

		<table border="0" cellspacing="0" cellpadding="0" class="tblbg"><tr><td>

		<table border="0" cellspacing="1" width=350>

		<tr>

			<Td class="tbltop" colspan="3"><?=$T['Add a User'];?></td>

		</tr>

	<? if ($curuserlist) { ?>

		<tr>

			<td class="row1"><div align=right><?=$T['Existing Domain User'];?>: </div></td>

			<td class="row2" align=left>

				<select name="data[domainuser]">

					<option value=''><?=$T['Please Select'];?></option>

					<?

					for ($i=0; $row = mysql_fetch_array($curuserlist); $i++) {

						echo "<option value='".$row["username"]."'>".$row["username"]."</option>\n";

					}

					?>

				</select>

			</td>

		</tr>

		<tr>

			<td class="normal" colspan=2><div align=center><?=$T['Or'];?></div></td>

		</tr>

	<? } ?>

		<tr>

			<td class="row1"><div align=right><?=$T['Username'];?>: </div></td>

			<td class="row2" align=left><input type="text" name="htuser"></td>

		</tr>

		<tr>

			<td class="row1"><div align=right><?=$T['Password'];?>: </div></td>

			<td class="row2" align=left><input type="text" name="htpasswd"></td>

		</tr>

		</table>

		</td></tr></table>

			<div align=right><nobr>

			<input type="submit" value="<?=$T['Add'];?>" class="check">



    	    </nobr></div>

		</td></tr></table>

		</p>

		</form>



		<? if (isset($userarray) && is_array($userarray)) { ?>



		<form action="/?url=<?=$url?>&cp=<?=$cp?>&user=<?=$user?>&action=hta" method="post">
		<input type=hidden name=data[dir] value="<?=$dir?>">

		<p align=center>

		<input type=hidden name=data[action] value='deleteuser'>

		<table border="0" cellspacing="0" cellpadding="0"><tr><td>

		<table border="0" cellspacing="0" cellpadding="0" class="tblbg"><tr><td>

		<table border="0" cellspacing="1" width=350>

		<tr>

			<Td class="tbltop" colspan="3"><?=$T['Delete a User'];?></td>

		</tr>

		<tr>

			<td class="row1"><div align=right><?=$T['Username'];?>: </div></td>

			<td class="row2" align=left>

			<select name=data[htuser]>

			<?

				for($i=0; $i<sizeOf($userarray[0]); $i++) {

					echo "<option value='".$userarray[0][$i]."'>".$userarray[1][$i]."</option>";

				}

			?>

			</td>

		</tr>

		</table>

		</td></tr></table>

			<div align=right><nobr>

			<input type="submit" value="<?=$T['Delete'];?>" class="check">



    	    </nobr></div>

		</td></tr></table>

		</p>

		</form>





		<form action="/?url=<?=$url?>&cp=<?=$cp?>&user=<?=$user?>&action=hta" method="post">
		<input type=hidden name=data[dir] value="<?=$dir?>">

		<p align=center>

		<input type=hidden name=data[action] value='changepass'>

		<table border="0" cellspacing="0" cellpadding="0"><tr><td>

		<table border="0" cellspacing="0" cellpadding="0" class="tblbg"><tr><td>

		<table border="0" cellspacing="1" width=350>

		<tr>

			<Td class="tbltop" colspan="3"><?=$T['Change a Password'];?></td>

		</tr>

		<tr>

			<td class="row1"><div align=right><?=$T['Username'];?>: </div></td>

			<td class="row2" align=left>

			<select name=data[htuser]>

			<?

				for($i=0; $i<sizeOf($userarray[0]); $i++) {

					echo "<option value='".$userarray[0][$i]."'>".$userarray[1][$i]."</option>";

				}

			?>

			</td>

		</tr>

		<tr>

			<td class="row1"><div align=right><?=$T['Password'];?>: </div></td>

			<td class="row2" align=left><input type="text" name="data[htpasswd]"></td>

		</tr>

		</table>

		</td></tr></table>

			<div align=right><nobr>

			<input type="submit" value="<?=$T['Change'];?>" class="check">



    	    </nobr></div>

		</td></tr></table>

		</p>

		</form>



		<? }

	}

	?>



		<?



	@ftp_quit($FTPid);



        if (file_exists($tmp_name)) {unlink($tmp_name);}

        if (file_exists($tmp2_name)) {unlink($tmp2_name);}



}







//******************************************************************************

// *** ACTION: view

// *** Displays the content of a file



elseif ($action == 'view') {



	$file_type = ftp_file_type(trim($file), $file_types);



	echo '<p><img src="'.$icon_dir.$icons['l'.$file_type].'" width="'.$l_icon_size.'" height="'.

		$l_icon_size.'"> <b>'.$currentdir.'/'.$file."</b></p>\n";



	if ($file_type == 'img') {

		echo '<img src="http://'.$domain.'/'.trim($webpath.'/'.$file, '/').'" border="1">';

	} elseif (ereg('^(txt|html|log|doc)$', $file_type)) {

		if (!isset($fstart)) $fstart = '0';



		if (!$FTPid = filemanager_login($personaldata)) { return; }



		$tmp_name = '/tmp/php'.uniqid(getmypid());

		if (!@ftp_get($FTPid, $tmp_name, $currentdir.'/'.$file, FTP_ASCII)) {

			echo 'error: viewing file';

		}



		@ftp_quit($FTPid);



		if ($fp = fopen($tmp_name, 'r')) {

			echo '<div style="border-style: solid; border-width: 1px;">';

			echo '<font size="1"><b>';

			$flast = $fstart + $fviewlen;

			$fpos = 0;

			while (!feof($fp)) {

			$nextline = fgets ($fp, 4096);

				if ($fpos >= $fstart) {

					echo nl2br(str_replace("\t", "&nbsp;&nbsp;&nbsp;&nbsp;",

						str_replace("  ","&nbsp;&nbsp;",htmlentities($nextline))));

				}

				if ($fpos++ >= $flast) break;

			}

			echo "</b></font>\n";

			echo '</div>';



			echo '<p>';

			if ($fstart > 0)

				$printout = "<a href='/?url=$url&cp=$cp&user=$user&action=view&data[dir]=$dir&file=$file&fstart=".

					($fstart-$fviewlen)."'>".$T['Previous']."</a>\n";



			if ($printout != '') {$printout .= ' | '; }



			if (!feof($fp))

				$printout .= "<a href='/?url=$url&cp=$cp&user=$user&action=view&data[dir]=$dir&file=$file&fstart=$flast'>".

					$T['Next']."</a>\n";



			if ($printout != '') {$printout .= ' | '; }



			$printout .= "<a href='$current_url&action=edit&data[dir]=$dir&file=$file'>".$T['Edit']."</a>";



			echo "$printout</p>";





		}

		fclose ($fp);

		unlink($tmp_name);



	} else {

		echo '<p><a href="http://'.$domain.'/'.trim($webpath.'/'.$file, '/').'">'.$T['Download'].'</a></p>'."\n";

	}



	echo "<p><a href='/?url=$url&cp=$cp&user=$user&data[dir]=$dir'>".$T['Return']."</a></p>\n";

}





//******************************************************************************

// *** ACTION: edit

// *** Edits the file



elseif ($action == 'edit') {



	if ($save == 'true') {

		if (!$FTPid = filemanager_login($personaldata)) { return; }



		$tmp_name = '/tmp/php'.uniqid(getmypid());

		file_put_contents($tmp_name,$rte1);

		// upload each temp file to the new path as the original name

			if (file_exists($tmp_name)) {

				$mode = FTP_ASCII;

				ftp_delete($FTPid, $currentdir.'/'.$file);

				if (@ftp_put($FTPid, $currentdir.'/'.$file, $tmp_name, $mode))

					echo '<p>'.$T['SaveSuccess'].' <b>'.$file."</b></p>\n";

				else

					echo '<p>'.$T['SaveError'].' <b>'.$file."</b></p>\n";

			}

		@ftp_quit($FTPid);

	}



	$file_type = ftp_file_type(trim($file), $file_types);



	echo '<p><img src="'.$icon_dir.$icons['l'.$file_type].'" width="'.$l_icon_size.'" height="'.

		$l_icon_size.'"> <b>'.$currentdir.'/'.$file."</b></p>\n";



	if (ereg('^(txt|html|log|doc)$', $file_type)) {



		if (!$FTPid = filemanager_login($personaldata)) { return; }



		$tmp_name = '/tmp/php'.uniqid(getmypid());

		if (!@ftp_get($FTPid, $tmp_name, $currentdir.'/'.$file, FTP_ASCII)) {

			echo 'error: loading file';

		}



		@ftp_quit($FTPid);



		if ($fp = fopen($tmp_name, 'r')) {

		?>

		<div align=left style='margin-left: 10px;'>

		<script language="JavaScript" type="text/javascript" src="richtext/richtext.js"></script>

		<form name="RTEDemo" action="<?=$current_url;?>" method="post" onsubmit="return submitForm();">

		<input type=hidden name=file value='<?=$file;?>'>

		<input type=hidden name=data[dir] value='<?=$dir;?>'>

		<input type=hidden name=act value='edit'>

		<input type=hidden name=save value='true'>

		<script language="JavaScript" type="text/javascript">



	function submitForm() {

		//make sure hidden and iframe values are in sync before submitting form

		//to sync only 1 rte, use updateRTE(rte)

		//to sync all rtes, use updateRTEs

		updateRTE('rte1');

		//updateRTEs();



		//change the following line to true to submit form

		return true;

	}



	<?

	$content = fread($fp, filesize($tmp_name));

	$content = rte_safe($content);

	?>//Usage: initRTE(imagesPath, includesPath, cssFile)

	initRTE("richtext/images/", "richtext/", "");

	</script>



	<script language="JavaScript" type="text/javascript">

	<!--

	//Usage: writeRichText(fieldname, html, width, height, buttons, readOnly)

	writeRichText('rte1', '<?=$content?>', 600, 350, true, false);

	//-->

	</script>



	<p><input type="submit" name="submit" value="<?=$T['Save'];?>"></p>

	</form>

		<?

		}

		fclose ($fp);

		unlink($tmp_name);



	}



	echo "<p><a href='/?url=$url&cp=$cp&user=$user&data[dir]=$dir'>".$T['Return']."</a></p>\n</div>";

}







//******************************************************************************

// *** ACTION: delete

// *** remove the selected files from the server

elseif (isset($_REQUEST['delete'])) {



	// display confirmation form

	if (!isset($_POST['confirm'])) {

		?>

		<form action="<?=$current_url;?>&data[dir]=<?=$dir?>&delete=1" method="post">

		<?

		foreach($_POST['files'] AS $file => $attrib) {

			?>

			<input type="hidden" name="files[<?=$file?>]" value="<?=$attrib?>">

			<p><?=$T['DeleteFile']?> <b><?=$currentdir.'/'.$file?></b>?</p>

			<p>

			<?

		}

		?>

		<table><tr>

		<td>

			<input type="submit" name="confirm" value="<?=$T['Delete']?>">

			</form>

		</td>

		<form action="<?=$current_url;?>&data[dir]=<?=$dir?>" method="post">

		<td>

			<input type="submit" name="cancel" value="<?=$T['Cancel']?>">

			</form>

		</td>

		</tr></table>

		<?

	}



	// Do actual delete

	elseif ($userdata['type'] != 'demo') {

		if (!$FTPid = filemanager_login($personaldata)) { return; }



		foreach($_POST['files'] AS $file => $attrib) {

			if ($attrib == 'd') {

				// is dir, for now dir must be empty but we should eventually do a recursive delete

				if (@ftp_rmdir($FTPid, $currentdir.'/'.$file)) {

					echo '<p>'.ucfirst($T['Dir'])." <b>$currentdir/$file</b> ".$T['DeleteSuccess']."</p>\n";

				} else {

					echo '<p>'.$T['DeleteError'].' '.$T['Dir']." <b>$currentdir/$file</b>! ".$T['IncorrectPermission']."</p>\n";

				}

			} elseif ($attrib == 'f') {

				// is file

				if (@ftp_delete($FTPid, $currentdir.'/'.$file)) {

					echo '<p>'.ucfirst($T['File'])." <b>$currentdir/$file</b> ".$T['DeleteSuccess']."</p>\n";

				} else {

					echo '<p>'.$T['DeleteError'].' '.$T['File'].' <b>'." <b>$currentdir/$file</b>! ".$T['IncorrectPermission']."</p>\n";

				}

			}

		}

		@ftp_quit($FTPid);



		echo '<p><a href="'.$current_url.'&data[dir]='.$dir.'">'.$T['Return'].'</a></p>'."\n";

	} elseif ($userdata['type'] == 'demo') {

		echo "<center>".$T['err']['demo user']."<br><a href='/?url=$url&cp=$cp&user=$user&data[dir]=$dir'>".$T['Return']."</a></center>\n";

	}

}



// *****************************************************************************

// *** ACTION: rename (rename)

// *** Renames files or directories

elseif (isset($_REQUEST['rename'])) {



	if (!isset($_POST['confirm'])) {

		?>

		<form action="<?=$current_url;?>=&action=ren&data[dir]=<?=$dir?>&rename=1?>" method="post">

		<?

		foreach($_POST['files'] AS $file => $attrib) {

			?>

			<p><?=$T['Rename']?> <b><?=$currentdir.'/'.$file?></b> <?=$T['To']?>:<p>

			<input type="text" name="files[<?=$file?>]" value="<?=$file?>" size="50">

			<?

		}



		?>

		<table><tr>

		<td>

			<input type="submit" name="confirm" value="<?=$T['Rename']?>">

			</form>

		</td>

		<form action="<?=$current_url;?>&data[dir]=<?=$dir?>" method="post">

		<td>

			<input type="submit" name="cancel" value="<?=$T['Cancel']?>">

			</form>

		</td>

		</tr></table>

		<?



	}



	elseif ($userdata['type'] != 'demo') {

		if (!$FTPid = filemanager_login($personaldata)) { return; }



		foreach($_POST['files'] AS $file => $attrib) {

			if (@ftp_rename($FTPid, $currentdir.'/'.$file, $currentdir.'/'.$attrib)) {

				echo "<p>".$T['RenameSuccess']." ".$T['File']." <b>$currentdir/$file</b> ".$T['To']." <b>$currentdir/$attrib</b></p>";

			} else {

				echo '<p>'. $T['RenameError']." <b>$currentdir/$file</b>! ".$T['IncorrectPermission']."!</p>";

			}

		}



		@ftp_quit($FTPid);



		echo "<p><a href='$current_url&data[dir]=$dir'>".$T['Return']."</a></p>\n";

	} elseif ($userdata['type'] == 'demo') {

		echo "<center>".$T['err']['demo user']."<br><a href='/?url=$url&cp=$cp&user=$user&data[dir]=$dir'>".$T['Return']."</a></center>\n";

	}

}



// *****************************************************************************

// *** ACTION: chmod

// *** Perfoms permission changes, using FTP to run as the file owner

elseif (isset($_REQUEST['chmod'])) {



	// Shows form with checkboxes to select new permissions

	if (!isset($_POST['confirm'])) {

		// TO DO: check the boxes according to current file permissions

		?>

		<form action="<?=$current_url;?>&action=chmod&data[dir]=<?=$dir?>&chmod=1" method="post">



		<? foreach ($_POST['files'] AS $file => $attrib) { ?>

			<p><b><?=$T['Chmod']?> <?=$currentdir.'/'.$file?></b></p>

			<table><tr>

			<td><b><?=$T['Owner']?>:</b></td>

			<td><input class="check" type="checkbox" name="files[<?=$file?>][user_read]"><?=$T['Read']?></td>

			<td><input class="check" type="checkbox" name="files[<?=$file?>][user_write]"><?=$T['Write']?></td>

			<td><input class="check" type="checkbox" name="files[<?=$file?>][user_exe]"><?=$T['Execute']?></td>

			</tr><tr>

			<td><b><?=$T['Group']?>:</b></td>

			<td><input class="check" type="checkbox" name="files[<?=$file?>][group_read]"><?=$T['Read']?></td>

			<td><input class="check" type="checkbox" name="files[<?=$file?>][group_write]"><?=$T['Write']?></td>

			<td><input class="check" type="checkbox" name="files[<?=$file?>][group_exe]"><?=$T['Execute']?></td>

			</tr><tr>

			<td><b><?=$T['World']?>:</b></td>

			<td><input class="check" type="checkbox" name="files[<?=$file?>][world_read]"><?=$T['Read']?></td>

			<td><input class="check" type="checkbox" name="files[<?=$file?>][world_write]"><?=$T['Write']?></td>

			<td><input class="check" type="checkbox" name="files[<?=$file?>][world_exe]"><?=$T['Execute']?></td>

			</tr></table>

		<? } ?>

		<table><tr>

		<td>

			<input type="submit" name="confirm" value="<?=$T['Modify']?>">

			</form>

		</td>

		<form action="<?=$current_url;?>&data[dir]=<?=$dir?>" method="post">

		<td>

			<input type="submit" name="cancel" value="<?=$T['Cancel']?>">

			</form>

		</td>

		</tr></table>

		<?

	}



	elseif ($userdata['type'] != 'demo') {

		if (!$FTPid = filemanager_login($personaldata)) { return; }



		foreach ($_POST['files'] AS $file => $attrib) {

			$newmode['u'] = 0;

			$newmode['g'] = 0;

			$newmode['w'] = 0;



			if (isset($attrib['user_read'])) $newmode['u'] += 4;

			if (isset($attrib['user_write'])) $newmode['u'] += 2;

			if (isset($attrib['user_exe'])) $newmode['u'] += 1;



			if (isset($attrib['group_read'])) $newmode['g'] += 4;

			if (isset($attrib['group_write'])) $newmode['g'] += 2;

			if (isset($attrib['group_exe'])) $newmode['g'] += 1;



			if (isset($attrib['world_read'])) $newmode['w'] += 4;

			if (isset($attrib['world_write'])) $newmode['w'] += 2;

			if (isset($attrib['world_exe'])) $newmode['w'] += 1;



			$new_mod = $newmode['u'].$newmode['g'].$newmode['w'];



			if (@ftp_site($FTPid, "chmod $new_mod $currentdir/$file")) {

				echo '<p>'.$T['ChmodSuccess']." <b>$currentdir/$file</b> ".$T['To']." ".$new_mod."</p>\n";

			} else {

				echo '<p>'.$T['ChmodError']." <b>$currentdir/$file</b>! ".$T['IncorrectPermission']."</p>\n";

			}

		}



		echo "<p><a href='/?url=$url&cp=$cp&user=$user&data[dir]=$dir'>".$T['Return']."</a></p>\n";



		@ftp_quit($FTPid);

	} else {

		echo "<center>".$T['err']['demo user']."<br><a href='/?url=$url&cp=$cp&user=$user&data[dir]=$dir'>".$T['Return']."</a></center>\n";

	}

}



// *****************************************************************************

// *** ACTION: (none) -> Directory listing

// *** List directories and files in current directory

else {



	if (!$FTPid = filemanager_login($personaldata)) { return; }



	// get directory listing

	if (!$list = @ftp_rawlist($FTPid, '-a '.$currentdir)) {

		echo '<p>'.$T['FTPerror'].'!</p>';

		@ftp_quit($FTPid);

		return;

	}



	@ftp_quit($FTPid);



	$filelist = array();



	foreach ($list AS $row) {



		// parse a standard unix ftp dir line into an array

		$exp = '/([pcdblsu-])'.		// 1. type

			'([rwxst-]{9})\s+'.	// 2. permissions

			'([0-9]+)\s+'.		// 3. links

			'(.+?)\s+'.		// 4. owner

			'(.+?)\s+'.		// 5. group

			'([0-9]+)\s+'.		// 6. size

			'([a-zA-Z]+)\s+'.	// 7. modified month

			'([0-9]+)\s+'.		// 8. modified day

			'([0-9:]+)\s+'.		// 9. modiefied time|year

			'(.+)/';		// 10. file name



		preg_match($exp, $row, $file);



		// get file's permissions

		$perm['u'] = 0;

		$perm['g'] = 0;

		$perm['o'] = 0;



		$u = substr($file[2], 0, 3);

		if (strpos($u, 'r') !== false) $perm['u'] += 4;

		if (strpos($u, 'w') !== false) $perm['u'] += 2;

		if (strpos($u, 'x') !== false) $perm['u'] += 1;

		$g = substr($file[2], 3, 3);

		if (strpos($g, 'r') !== false) $perm['g'] += 4;

		if (strpos($g, 'w') !== false) $perm['g'] += 2;

		if (strpos($g, 'x') !== false) $perm['g'] += 1;

		$o = substr($file[2], 6);

		if (strpos($o, 'r') !== false) $perm['o'] += 4;

		if (strpos($o, 'w') !== false) $perm['o'] += 2;

		if (strpos($o, 'x') !== false) $perm['o'] += 1;



		$stats['p'] = $perm['u'].$perm['g'].$perm['o'];



		// get file's size

		$stats['s'] = $file[6];



		// get the file's last modified date

		if (strpos($file[9], ':') !== false) {

			$stats['m'] = date($dateformat, strtotime($file[9].' '.$file[7].' '.$file[8]));

		} else {

			$stats['m'] = date($dateformat, strtotime($file[7].' '.$file[8].' '.$file[9]));

		}



		// get file's owner

		if ($pwuid = @posix_getpwuid(intval($file[4])))

			$stats['o'] = $pwuid['name'];

		else

			$stats['o'] = "<i>".$T['none']."</i>";



		// get file's group

		if ($gruid = @posix_getgrgid(intval($file[5])))

			$stats['g'] = $gruid['name'];

		else

			$stats['g'] = "<i>".$T['none']."</i>";



		// separate dirs into an array and files into another

		if ($file[10] != '.' && $file[10] != '..') {

			if (strpos($file[1], 'd') === 0) {

				$dirlist[] = $file[10];

				$dirstats[] = $stats;

			} elseif (strpos($file[1], 'l') === 0) {

				if (!$cfg['users_chrooted']) {

					if (is_dir($dir."/".realpath($file[10]))) {

						$dirlist[] = preg_replace("/ -> .*/", "", $file[10]);

						$dirstats[] = $stats;

					} else {

						$filelist[] = preg_replace("/ -> .*/", "", $file[10]);

						$filestats[] = $stats;

					}

				}

			} else {

				$filelist[] = $file[10];

				$filestats[] = $stats;

			}

		}

	}



        // Get cdup (parent directory)

        if ($dir) {

                $segs = explode ('/', $dir);



		$cdup = '';

                for ($i = 0; $i < count($segs) - 1; $i++) {

                        $cdup .= '/'.$segs[$i];

                }

		$cdup = substr($cdup, 1);

        }



	?>

	<form action="<?=$current_url;?>&data[dir]=<?=$dir?>&file=<?=$file?>" method="post">



	<img src="<?=$icon_dir?><?=$icons['lofolder']?>" width="<?=$l_icon_size?>" height="<?=$l_icon_size?>"><b><?=$currentdir?></b>



	<p>

	<a href="<?=$current_url;?>&data[dir]=<?=$dir?>&action=upload"><?=$T['Upload Files'];?></a> -

	<a href="<?=$current_url;?>&data[dir]=<?=$dir?>&action=newdir"><?=$T['New Directory'];?></a> -

	<a href="<?=$current_url;?>&data[dir]=<?=$dir?>&action=hta"><?=$T['Protect Directory'];?></a>

	</p>



	<table width="100%" border="0" cellspacing="0" cellpadding="0" class="tblbg"><tr><td>

	<table width="100%" border="0" cellspacing="1">

 	<tr>

		<td class="tbltop"></td>

		<td class="tbltop"></td>

		<td class="tbltop"><?=$T['Filename'];?></td>

		<td class="tbltop"><?=$T['Size'];?></td>

		<td class="tbltop"><?=$T['Date/Time'];?></td>

		<td class="tbltop"><?=$T['Owner'];?></td>

		<td class="tbltop"><?=$T['Group'];?></td>

		<td class="tbltop"><?=$T['Mode'];?></td>

	</tr>

        <?



	// print out parent directory

	echo '<tr class="row1"><td></td><td><img src="'.$icon_dir.$icons['sparent'].'" width="'.$s_icon_size.

		'" height="'.$s_icon_size.'"></td><td colspan="6"><a href="'.$current_url;

        if (isset($cdup)) {

		echo '&data[dir]='.$cdup.'">'.$T['Parent Folder'].'</a></td></tr>'."\n";

        } elseif (isset($dir)) {

  		echo '">'.$T['Parent Folder'].'</a></td></tr>'."\n";

        }



	$i = 0;



	// print out list of directories

        if (isset($dirlist) && is_array($dirlist)) {

                sort($dirlist);

                foreach ($dirlist as $key => $nextfile) {

			// wordwrap dirname

                        $wrappedfile = wordwrap($nextfile, 25, '<br>', 1);



			?>

			<tr class="<?=(($i % 2) == 0 ? 'row2' : 'row1')?>" valign="top">

			<td><input type="checkbox" name="files[<?=$nextfile?>]" value="d"></td>

			<td><img src="<?=$icon_dir?><?=$icons['sfolder']?>" width="<?=$s_icon_size?>" height="<?=$s_icon_size?>"></td>

			<td style="font-size:12"><a href="<?=$current_url;?>&data[dir]=<?=trim($dir.'/'.$nextfile, '/')?>"><?=$wrappedfile?></a></td>

			<td align="right" style="font-size:12" valign="top"><?=convert_bytes($dirstats[$key]['s'], $metric).strtoupper($metric)?></td>

			<td align="center" style="font-size:12"><?=$dirstats[$key]['m']?></td>

 			<td style="font-size:12"><?=$dirstats[$key]['o']?></td>

 			<td style="font-size:12"><?=$dirstats[$key]['g']?></td>

			<td style="font-size:12"><?=$dirstats[$key]['p']?></td>

			</tr>

			<?

			$i++;

                }

        }



	// print out list of files

        $totalfsize = 0;

        if (isset($filelist)) {

                sort($filelist);

                foreach ($filelist as $key => $nextfile) {

			// wordwrap filename

                        $wrappedfile = wordwrap($nextfile, 25, '<br>', 1);

			$icon = 's'.ftp_file_type($nextfile, $file_types);



                        ?>

			<tr class="<?=(($i % 2) == 0 ? 'row2' : 'row1')?>" valign="top">

			<td><input type="checkbox" name="files[<?=$nextfile?>]" value="f"></td>

			<td><img src="<?=$icon_dir?><?=$icons[$icon]?>" width="<?=$s_icon_size?>" height="<?=$s_icon_size?>"></td>

			<td style="font-size:12"><a href='<?=$current_url;?>&action=view&data[dir]=<?=$dir?>&file=<?=$nextfile?>'><?=$wrappedfile?></a></td>

			<td align="right" style="font-size:12"><?=convert_bytes($filestats[$key]['s'], $metric).strtoupper($metric)?></td>

			<td align="center" style="font-size:12"><?=$filestats[$key]['m']?></td>

			<td style="font-size:12"><?=$filestats[$key]['o']?></td>

			<td style="font-size:12"><?=$filestats[$key]['g']?></td>

			<td style="font-size:12"><?=$filestats[$key]['p']?></td>

			</tr>

			<?



                        $totalfsize += $filestats[$key]['s'];

			$i++;

                }

        }



	?>

	</table></td></tr></table>



        <p><?=convert_bytes($totalfsize, $metric).strtoupper($metric)?> <?=$T['allocated in'];?> <?=count($filelist)?> <?=$T['files'];?></p>



	<!--<input type="submit" name="move" value="<?=$T['Move'];?>">-->

	<input type="submit" name="chmod" value="<?=$T['Chmod']?>">

	<input type="submit" name="rename" value="<?=$T['Rename']?>">

	<input type="submit" name="delete" value="<?=$T['Delete']?>">

	</form>



	<?

}
